package com.anytrek.cloudopenfeign.fallback;

import com.anytrek.cloudcommon.utils.ApiResult;
import com.anytrek.cloudopenfeign.openfeign.UsersClient;
import lombok.extern.log4j.Log4j2;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @ ClassName UsersClientFallbackFactory
 * @ Author Alex2
 * @ Date 2025/8/28 9:28
 **/
@Component
@Log4j2
public class UsersClientFallbackFactory implements FallbackFactory<UsersClient> {

    @Override
    public UsersClient create(Throwable cause) {
        return new UsersClient() {
            @Override
            public ApiResult getUserById(Integer id) {
                log.error("远程调用 cloud-user : getUserById 失败", cause);
                return ApiResult.error("远程调用 cloud-user : getUserById 失败");
            }

            @Override
            public ApiResult deductBalance(Integer id, Integer amount) {
                log.error("远程调用 cloud-user : deductBalance 失败", cause);
                return ApiResult.error("远程调用 cloud-user : deductBalance 失败");
            }
        };
    }
}